package com.smart.common;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
import java.util.Collections;
import java.util.List;
import java.util.Map;

@ApiModel(description = "分页查询响应")
public class PageInfo<T> implements Serializable {

  private static final long serialVersionUID = 1L;
  @ApiModelProperty("当前页数")
  private int pageNum;
  @ApiModelProperty("每页数量")
  private int pageSize = 20;
  @ApiModelProperty("总数量")
  private long total;
  @ApiModelProperty("数据")
  private List<T> list;
  @ApiModelProperty("扩展信息")
  private Map<String, Object> extInfo;

  public PageInfo() {
  }

  public PageInfo(Integer pageNum, Integer pageSize, List<T> list, long total) {
    this.pageNum = pageNum;
    this.pageSize = pageSize;
    this.list = list;
    this.total = total;
  }

  public PageInfo(Integer pageNum, Integer pageSize, List<T> list, long total, Map<String, Object> extInfo) {
    this.pageNum = pageNum;
    this.pageSize = pageSize;
    this.list = list;
    this.total = total;
    this.extInfo = extInfo;
  }

  public static <T> PageInfo buildEmpty() {
    return new PageInfo(1, 20, Collections.emptyList(), 0);
  }

  public static <T> PageInfo buildEmpty(Map<String, Object> extInfo) {
    return new PageInfo(1, 20, Collections.emptyList(), 0, extInfo);
  }

  public static <T> PageInfo build(Integer pageNum, Integer pageSize, List<T> list, long total) {
    return new PageInfo(pageNum, pageSize, list, total);
  }

  public static <T> PageInfo build(Integer pageNum, Integer pageSize, Map<String, Object> extInfo) {
    return new PageInfo(pageNum, pageSize, Collections.emptyList(), 0, extInfo);
  }

  public static <T> PageInfo build(Integer pageNum, Integer pageSize, List<T> list, long total, Map<String, Object> extInfo) {
    return new PageInfo(pageNum, pageSize, list, total, extInfo);
  }

  public int getPageNum() {
    return pageNum;
  }

  public void setPageNum(int pageNum) {
    this.pageNum = pageNum;
  }

  public int getPageSize() {
    return pageSize;
  }

  public void setPageSize(int pageSize) {
    this.pageSize = pageSize;
  }

  public long getTotal() {
    return total;
  }

  public void setTotal(long total) {
    this.total = total;
  }

  public List<T> getList() {
    return list;
  }

  public void setList(List<T> list) {
    this.list = list;
  }

  public Map<String, Object> getExtInfo() {
    return extInfo;
  }

  public void setExtInfo(Map<String, Object> extInfo) {
    this.extInfo = extInfo;
  }
}
